Create ClientSessionGroup for managing multiple session connections.#639
Merged
ihrpr merged 6 commits intomodelcontextprotocol:mainfrom May 13, 2025
Merged
Create ClientSessionGroup for managing multiple session connections.#639ihrpr merged 6 commits intomodelcontextprotocol:mainfrom
ClientSessionGroup for managing multiple session connections.#639ihrpr merged 6 commits intomodelcontextprotocol:mainfrom
Conversation
This abstraction concurrently manages multiple MCP session connections. Tools, resources, and prompts are aggregated across servers. Servers may be connected to or disconnected from at any point after initialization. This abstractions can handle naming collisions using a custom user-provided hook.
ihrpr
requested changes
May 8, 2025
Contributor
ihrpr
left a comment
There was a problem hiding this comment.
Thank you for working on this!
We need to make sure that this ClientSessionGroup/Host abstraction supports all current transports in SDK
…onGroup This change introduces additional support for the other MCP transports and includes respective server parameter types to align with the stdio client implementation.
ihrpr
requested changes
May 9, 2025
Contributor
ihrpr
left a comment
There was a problem hiding this comment.
thank you so much for the quick turnaround!
there a few things we need to add:
- ClientSessionGroup to implement
__aenter__/__aexit__ - Ability to use
async with ClientSessionGroup(): - disconnect_from_server removes sessions from tracking but doesn't remove them from _exit_stack
- add documentation on how to use
215d0bc to
fcbdd79
Compare
cca631c to
d4a28ca
Compare
ihrpr
requested changes
May 12, 2025
Contributor
ihrpr
left a comment
There was a problem hiding this comment.
Some small changes and we are good to merge! Thank you
d4a28ca to
a42f953
Compare
This changes enables context management for setting up and tearing down async exit stacks durring server connection and disconnection respectively. Documentation has been added to show an example use case that demonstrates how `ClientSessionGroup` can be used with `async with`.
595e777 to
e798eeb
Compare
amirh
reviewed
May 13, 2025
| the client and can be accessed via the session. | ||
|
|
||
| Example Usage: | ||
| name_fn = lambda name, server_info: f"{(server_info.name)}-{name}" |
There was a problem hiding this comment.
Is it possible that both a tool name and a server_info name would conflict? would there be enough information for the hook to disambiguate?
Contributor
|
related to #9 |
This was referenced Oct 7, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This abstraction concurrently manages multiple MCP session connections.
Tools, resources, and prompts are aggregated across servers. Servers may be connected to or disconnected from at any point after initialization.
This abstractions can handle naming collisions using a custom user-provided hook.
Motivation and Context
This change alleviates the need for users to re-implement a multi-session "manager" anytime more than 1 session needs to be established.
Testing
Code branches are covered via pytest unit tests.
Breaking Changes
This is a no-op as it introduces a new class without modifying existing dependencies.
Types of changes
Checklist